package org.maylove.wuziqi.dao;

import jakarta.transaction.Transactional;
import org.maylove.wuziqi.pojo.notice.Notice;
import org.maylove.wuziqi.service.NoticeService;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NoticeDao extends JpaRepository<Notice, Long> {

    @Query(value = "SELECT n FROM Notice n ORDER BY n.noticeId DESC LIMIT 3")
    List<Notice> getMainNotice();

    @Query(nativeQuery = true, value = "SELECT * FROM notice ORDER BY notice_id DESC LIMIT ?,?")
    List<Notice> getAllNotice(Integer pageBegin, Integer pageNum);

    Notice findByNoticeId(Long noticeId);

    @Transactional
    @Modifying
    @Query(value = "DELETE FROM Notice n WHERE n.noticeId=?1")
    void deleteByNoticeId(Long noticeId);

}
